/*
 * Copyright 2005-2013 biz-united. All rights reserved.
 * Support: http://www.biz-united.com.cn
 * License: http://www.biz-united.com.cn/?page_id=5&act=3
 */
package net.biz.service.impl;

import net.biz.Page;
import net.biz.Pageable;
import net.biz.dao.impl.RecordDaoImpl;
import net.biz.dto.RecordDto;
import net.biz.entity.Admin;
import net.biz.entity.AdminRecord;
import net.biz.service.RecordService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Service - 商品
 * 
 * @version 3.0
 */
@Service("recordServiceImpl")
public class RecordServiceImpl extends BaseServiceImpl<AdminRecord, Long> implements RecordService {
	@Resource(name = "recordDaoImpl")
	private RecordDaoImpl recordDaoImpl;

	@Resource(name = "recordDaoImpl")
	public void setBaseDao(RecordDaoImpl recordDaoImpl) {
		super.setBaseDao(recordDaoImpl);
	}

	@Override
	public Page<AdminRecord> findPage(Admin admin, Date beginDate, Date endDate, Pageable pageable) {
		return recordDaoImpl.findPage(admin,beginDate, endDate ,pageable);
	}

	@Override
	public List<RecordDto> getRecordDtoList(Admin admin, Date beginDate, Date endDate, Pageable pageable) {
		List<AdminRecord> adminRecordList = recordDaoImpl.getRecordList(admin,beginDate, endDate ,pageable);
		List<RecordDto> recordDtOList = new ArrayList<>();
		try {
			if(adminRecordList!=null){
                for(AdminRecord adminRecord:adminRecordList){
                    RecordDto recordDto = new RecordDto();
                    BeanUtils.copyProperties(recordDto,adminRecord);
                    String isScheme = "否";
                    if(adminRecord.getIsScheme()!=null){
                        isScheme = adminRecord.getIsScheme()? "是":"否";
                    }
                    recordDto.setIsScheme(isScheme);
                    recordDtOList.add(recordDto);
                }
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
		return recordDtOList;
	}
}